package com.leyou.item.service;

import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.pojo.Category;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;


    //获取分类的列表
    public List<Category> queryCategoryByPid(Long id) {
        Category category = new Category();
        category.setParentId(id);
        return categoryMapper.select(category);

       /* List<Category> categoryList=  categoryMapper.queryCategory(id);
        return categoryList;*/

    }
    //获取回显得分类id
    public List<Category> queryByBrandId(Long bid) {
        return categoryMapper.queryByBrandId(bid);
    }

   //获取分类的名字
    public String queryNameByCids(List<Long> ids){

        List<String> collect = this.categoryMapper.selectByIdList(ids).stream().map(category -> category.getName()).collect(Collectors.toList());
        String join = StringUtils.join(collect, "/");
        return join;

    }
}
